package com.pms.servlet;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pms.entity.Ideas;
import com.pms.entity.Project;
import com.pms.entity.Users;
import com.pms.service.IdeaService;
import com.pms.util.GetSession;

public class NewIdeaServlet extends HttpServlet {


	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setCharacterEncoding("utf-8");
		request.getRequestDispatcher("/WEB-INF/newIdea.jsp").forward(request, response);
	
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setCharacterEncoding("utf-8");
		String title=request.getParameter("title");
		String note=request.getParameter("note");
		
		System.out.println(title+note);
		Project pro = (Project)GetSession.getSession(request).getAttribute("pro");
		String proid=pro.getPro_id();
		System.out.println(proid);
		
		Users user = (Users)GetSession.getSession(request).getAttribute("user");
		
		
		Ideas idea=new Ideas();
		idea.setTitle(title);
		idea.setNote(note);
		idea.setUserid(user.getUser_id());
		idea.setProid(proid);
		
		new IdeaService().save(idea);

		response.sendRedirect("idea.jspx");
	}

}
